<?php
class Default_Model_Filter extends Zend_Db_Table
{
	
	//Model nay su dung cau lenh join nen khong can khai bao name table su dung cho Model nay
	protected $_db;
	
	public function __construct()
	{
		$this->_db = Zend_Registry::get('connectDb');
	
	
	}
	public function getFeatureCategory() //De hieu duoc function nay xem column id_feature_category cua 2 tables(feature_detail va feature_category)
	{									
		$select = $this->_db->select()   //Xem lai dinh nghia INNER join(co the viet join).Outerjoin(joinleft,joinright,joinfull)
							->from('feature_category as C') //feature_category la table left.Nghia la joinLeft lay ca nhung C.id_feature_category ma table feature_detail khong co 
							->joinLeft('feature_detail As D','C.id_feature_category=D.id_feature_category',array('D.name','D.id_feature_detail'))
							;
		$result = $this->_db->fetchAll($select); //$result la mot array luu tru gia tri 'D.name' va 'D.id_feature_detail'
		
		$name = array(); //Khai bao mang ten 'name' de su dung duoi
		foreach($result as $value)
		{
			 $name[$value['namecategory']][$value['id_feature_detail']]=$value['name']; //$name['hangsanxuat']['1']=$value['Apple']
		}																				//$name['hangsanxuat']['2']=$value['Acer']
																						//$name['DongCPU']['8']=$value['Intel Atom']; $name['DongCPU']['9']=$value['Intel celeron']
		return $name;
	}
	public function getProduct($id)
	{
		$select = $this->_db->select() //protected _db duoc khai bao phia tren
						->where('id_feature_detail =?',$id,INTEGER)
						->from('product_has_feature_detail As D')
						->joinLeft('sanpham As P','D.id_product=P.IdSP',array('IdSP','TenSP','TomTat','ChiTiet','Image','luotxem'));
	
		$result = $this->_db->fetchAll($select);
	
		return $result;					
		
	}
}